package com.mo.controller;

import com.mo.common.Result;
import com.mo.entity.User;
import com.mo.service.RedisService;
import com.mo.service.UserService;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;

@RestController
public class RedisTestController {

    @Resource
    private RedisService redisService;
    @Resource
    private UserService userService;

    @GetMapping("redis")
    public Result redis() {
        List<User> users = userService.list();
        users.forEach(item -> redisService.setList("list", item));

        List<User> list = redisService.getList("list", 0L, users.size());
        list.forEach(System.out::println);


        HashMap<String, Object> map = new HashMap<>();
        map.put("name", "it");
        map.put("emps", users);
        map.put("time", System.currentTimeMillis());
        redisService.setObject("map", map);
        System.out.println("===================================================");

        Object rMap = redisService.getObject("map");
        System.out.println(rMap);

        return Result.success(null, rMap);
    }
}
